from openpyxl import load_workbook
import os
import sys

def check_excel_structure():
    try:
        # 获取当前脚本所在目录
        current_dir = os.path.dirname(os.path.abspath(__file__))
        excel_path = os.path.join(current_dir, '烤机自动记录表.xlsx')
        
        print(f"尝试打开Excel文件: {excel_path}")
        print(f"文件是否存在: {os.path.exists(excel_path)}")
        
        if not os.path.exists(excel_path):
            print(f"错误: Excel文件不存在: {excel_path}")
            return
            
        wb = load_workbook(excel_path)
        
        print("\nExcel文件结构检查:")
        print("=" * 50)
        
        # 检查所有工作表
        print("\n工作表列表:")
        for sheet_name in wb.sheetnames:
            print(f"- {sheet_name}")
        
        # 检查模板工作表
        if 'template' in wb.sheetnames:
            template_sheet = wb['template']
            print("\n模板工作表结构:")
            print(f"总行数: {template_sheet.max_row}")
            print(f"总列数: {template_sheet.max_column}")
            
            # 打印前几行内容
            print("\n前5行内容:")
            for row in template_sheet.iter_rows(min_row=1, max_row=5, values_only=True):
                print(row)
        else:
            print("\n警告: 未找到名为'template'的工作表!")
            print("当前工作表:")
            for sheet_name in wb.sheetnames:
                print(f"- {sheet_name}")
        
        wb.close()
        
    except Exception as e:
        print(f"发生错误: {str(e)}")
        print(f"错误类型: {type(e).__name__}")
        import traceback
        traceback.print_exc()

if __name__ == '__main__':
    check_excel_structure() 